/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Professor;
import java.sql.SQLException;
import java.util.List;
import java.sql.ResultSet;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import util.Debug;

/**
 *
 * @author daz
 */
public class ProfessorDao extends SimpleJdbcDaoSupport {

    public List<Professor> getListProfessors() {
        String query = "SELECT * FROM professors p";
        return getSimpleJdbcTemplate().query(query, new ProfessorMapper());
    }

    public void insertNewProfessor(Professor professor) {
        String query = "INSERT INTO professors(name) VALUES('" + professor.getName() + "') ;";
        getJdbcTemplate().execute(query);
    }

    private class ProfessorMapper implements ParameterizedRowMapper<Professor> {

        @Override
        public Professor mapRow(ResultSet rs, int rowNum) throws SQLException {
            Debug.d("row num :" + rowNum);
//            Professor professor = new Professor();
            Professor professor = new Professor();
            professor.setId(rs.getInt("id"));
            professor.setName(rs.getString("name"));
//            professor.setIsHust(rs.getInt("is_hust"));
//            professor.setStartTime(rs.getString("start_time"));
//            professor.setEndTime(rs.getString("end_time"));
            return professor;
        }
    }
}
